<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/12
 * Time: 16:27
 */

namespace App\Service;


use App\Dao\UserDao;
use App\Exception\BusinessException;
use Hyperf\Di\Annotation\Inject;

class SysService extends Service
{

    /**
     * @Inject()
     * @var UserDao
     */
    private $userDao;

    /**
     * 用户登录
     * @param string $username
     * @param string $password
     * @return mixed
     */
    public function login(string $username, string $password)
    {
        $sysUser = $this->userDao->getUserByName($username);

        if (!password_verify($password, $sysUser->password)) {
            throw new BusinessException('用户名或密码错误');
        }
        if ($sysUser->status != 1) {
            throw new BusinessException('该用户禁止登陆');
        }
        return $sysUser;
    }

    /**
     * 获取系统用户信息
     * @param $userId
     * @return mixed
     */
    public function getUserData($userId)
    {
        return $this->userDao->first($userId);
    }

}